package com.mangowang.module.main.ui;


import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.google.protobuf.InvalidProtocolBufferException;
import com.mangowang.lib.common.base.BaseActivity;
import com.mangowang.lib.common.net.Apis;
import com.mangowang.lib.common.net.NetworkManager;
import com.mangowang.lib.common.net.interfaces.OnRequestCallBack;
import com.mangowang.lib.common.proto.Recharge;
import com.mangowang.lib.common.util.StatusBarUtil;
import com.mangowang.module.main.R;
import com.mangowang.module.main.R2;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

public class AccountActivity extends BaseActivity {

    Unbinder unbinder;
    @BindView(R2.id.tab_layout)
    TabLayout tabLayout;
    @BindView(R2.id.view_pager)
    ViewPager viewPager;
    @BindView(R2.id.back_iv)
    ImageView backIv;

    private List<Fragment> fragmentList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account);
        unbinder = ButterKnife.bind(this);
        StatusBarUtil.setRootViewFitsSystemWindows(this, false);
        StatusBarUtil.setTranslucentStatus(this);
        backIv.setOnClickListener(v -> finish());
        initView();
    }



    private void initView() {

        // 获取标题
        List<String> titles = new ArrayList<>();
        fragmentList = new ArrayList<>();
        titles.add(getIntent().getStringExtra("title"));
        fragmentList.add(AccountFragment.NewInstance(getIntent().getStringExtra("type")
                ,getIntent().getStringExtra("balance"),getIntent().getIntExtra("fragmentPosition",0)));
        viewPager.setOffscreenPageLimit(titles.size());
        viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles.get(position);
            }

        });
        //设置图标
        tabLayout.setupWithViewPager(viewPager);
    }
}